package cn.topcodes.tcsf.admin.service;

import cn.topcode.unicorn.utils.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.PostConstruct;

/**
 * 数据完整性检查规则
 */
public abstract class IntegrityCheckRule {

    @Autowired
    private IntegrityCheckService integrityCheckService;

    private String id;

    @PostConstruct
    public void init() {
        this.id = UuidUtil.getUUID();
        integrityCheckService.addRule(this);
    }

    /**
     * 规则名称
     * @return
     */
    public abstract String getName();

    /**
     * 规则检查
     */
    public abstract String check();

    public void output(String text) {
        if(this.integrityCheckService.getCallback() != null) {
            this.integrityCheckService.getCallback().onRuleChecking(this, text);
        }
    }

    public void error(String err) {
        if(this.integrityCheckService.getCallback() != null) {
            this.integrityCheckService.getCallback().onRuleCheckError(this, err);
        }
    }

    public String getId() {
        return this.id;
    }
}
